﻿using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using HOPU.OnlineSchool.Application.Dashboard.Dtos;
using HOPU.OnlineSchool.Core;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HOPU.OnlineSchool.Application.Dashboard.Services
{
    public class DashboardService : IDashboardService, ITransient
    {
        private readonly IRepository<StatisticsDaily> _statisticsRepository;

        public DashboardService(IRepository<StatisticsDaily> statisticsRepository)
        {
            this._statisticsRepository = statisticsRepository;
        }

        public async Task<EchartsDto> GetDataSync()
        {
            EchartsDto echartDto = new EchartsDto();
            List<StatisticsDaily> list = await _statisticsRepository.AsQueryable().ToListAsync();
            echartDto.XData = list.Select(m => m.DateCalculated).ToList();
            echartDto.YData = list.Select(m => m.LoginNum).ToList();
            return echartDto;
        }
    }
}
